const {merge} = require("webpack-merge")
const path = require("path")
const baseConfig = require("./webpack.config.base")
const buildConfig = require("./webpack.build")
// const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin")
const webpack = require("webpack")
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
// const UglifyJsPlugin = require("uglifyjs-webpack-plugin")
const theme = require("./theme"); //引入antd主题修改
const config= {
  module: {
    rules: [
      {
        test: /\.css$/,
        // include: path.resolve(__dirname, "./src"),
        use: [
          {
            loader: MiniCssExtractPlugin.loader // 通过 link 标签注入
          },
          {
            loader: "css-loader",
            options: {
              sourceMap: true,
              importLoaders: 1,
              // modules: {
              //   localIdentName: "[local]--[hash:base64:5]"
              // }

            }
          },
          {
            loader: "postcss-loader"
          }
        ]
      },
      {
        test: /\.less$/,
        // include: path.resolve(__dirname, "./src"),
        use: [
          {
            loader: MiniCssExtractPlugin.loader
          },
          {
            loader: "css-loader",
            options: {
              sourceMap: true,
              importLoaders: 1
              // modules: {
              //   localIdentName: "[local]--[hash:base64:5]"
              // }

            }
          },
          {
            loader: "postcss-loader"
          },
          {
            loader:"less-loader",
            options:{
              lessOptions: {
                javascriptEnabled:true,
                modifyVars: theme,
              }
            }
          }
        ]
      },
    ]
  },
  plugins: [
    new webpack.NoEmitOnErrorsPlugin(), //暂时用途不详，类似于try catch  遇见错误不停止代码
    new MiniCssExtractPlugin({
      filename: "[name].[chunkhash:8].css",
      chunkFilename: "[name].[chunkhash:8].css"
    }),
  ]
}
baseConfig.output.path = path.resolve(__dirname, process.env.NODE_ENV_OUTPUT);
module.exports = merge(baseConfig, config)
